package com.itheima.health.service.impl;

import com.itheima.health.dto.ReportDto;
import com.itheima.health.service.ReportService;
import com.itheima.health.mapper.ReportMapper;
import com.itheima.health.vo.ReportVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author 十一
 * @Description
 * @create 2020-11-06-18:53
 */
@Service
@Transactional
public class ReportServiceImpl implements ReportService {


    /**
     * 套餐占比
     */
    @Autowired
    private ReportMapper reportMapper;

    @Override
    public List<Map> setmealProportion() {

        return reportMapper.setmealProportion();
    }

    @Override
    public ReportVo memberReportByLastYear(ReportDto reportDto) {
        String begin = reportDto.getBegin();
        String end = reportDto.getEnd();
        List<Map> mapList = reportMapper.memberReportByLastYear(begin,end);
        System.out.println(mapList);
        ReportVo reportVo= new ReportVo();
        List<Long> memberCountsList =   new ArrayList<>();
        List<String> monthList =  new ArrayList<>();
        for (int i = 0; i < mapList.size(); i++) {
            Long memberCounts = (Long) mapList.get(i).get("memberCounts");
             memberCountsList.add(memberCounts);
            String  yearAndMonth = (String) mapList.get(i).get("yearAndMonth");
            monthList.add(yearAndMonth);
        }
        reportVo.setMemberCounts(memberCountsList);
        reportVo.setMonthList(monthList);


        return reportVo;

        //拿到日历的集合 2019-03   2019-08
        //遍历集合 通过subString 截取月份和年份
        //判断年份是否相同
        //相同
        //(起始年份，结束年份，起始月份，结束月份)

        //判断是否跨年
        //如果跨年，起始年份 起始月份 结束月份为12月
        //结束年份 起始月份为1月 结束月份
        //if(结束年份-起始年份>1){return new}
    }
}
